#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

int num_zero_supply_counts(struct gameState *state)
{
	int i;
	int count = 0;

	for (i = 0; i < 27; i++) {
		if (state->supplyCount[i] == 0) {
			count++;
		}
	}

	return count;
}

void test_isGameOver(struct gameState *state)
{
	int success;
	int i;
	int num_zero_counts;

	/* Test One: Provice is 0 */
	state->supplyCount[province] = 0;
	success = isGameOver(state);
	if (success) {
		printf("Test One: PASS\n");
	} else {
		printf("Test Two: FAIL\n");
	}

	/* Test Two: Provice is not 0 */
	state->supplyCount[province] = 42;
	success = !isGameOver(state);
	if (success) {
		printf("Test Two: PASS\n");
	} else {
		printf("Test Two: FAIL\n");
	}

	/* Test Three: three supply counts are zero */
	state->supplyCount[0] = 0;
	state->supplyCount[1] = 0;
	state->supplyCount[2] = 0;
	success = isGameOver(state);
	if (success) {
		printf("Test Three: PASS\n");
	} else {
		printf("Test Three: FAIL\n");
	}

	/* Test Four: last three are zero */
	state->supplyCount[0] = 42;
	state->supplyCount[0] = 42;
	state->supplyCount[0] = 42;

	state->supplyCount[24] = 0;
	state->supplyCount[24] = 0;
	state->supplyCount[24] = 0;
	success = isGameOver(state);
	if (success) {
		printf("Test Four: PASS\n");
	} else {
		printf("Test Five: FAIL\n");
	}

	/* Test Five: random supply counts */
	num_zero_counts = 0;

	do {
		for (i = 0; i < treasure_map + 1; i++) {
			state->supplyCount[i] = (int)floor(Random() * 10);
		}

		num_zero_counts = num_zero_supply_counts(state);
	} while (num_zero_counts < 3);

	success = isGameOver(state);
	if (success) {
		printf("Test Five: PASS\n");
	} else {
		printf("Test Five: FAIL\n");
	}
}

int main(void)
{
	struct gameState state;
	test_isGameOver(&state);
	return EXIT_SUCCESS;
}